from rest_framework import serializers

# 省级信息序列化器(与模型类相关,所以继承ModelSerializer)
from areas.models import Area


class AreaSerializer(serializers.ModelSerializer):
    class Meta:
        model = Area
        fields = ['id', 'name']


# 市县区级信息
# 设置模型类时,就可以通过省级.subs获取到下面所有的市级信息,需要字段id,name,subs
class SubAreaSerializer(serializers.ModelSerializer):
    subs = AreaSerializer(many=True,read_only=True)
    class Meta:
        model=Area
        fields=['id','name','subs']




